package study.mapper;

import org.apache.ibatis.annotations.*;
import study.pojo.Brand;

import java.util.List;

public interface BrandMapper {


    /*
    * 查询所有
    * */
    @Select("select * from tb_brand")
    @ResultMap("brandResultMap")
    List<Brand> selectAll();

    /*
    * 添加
    * */
    @Insert("insert into tb_brand (brand_name,company_name,ordered,description,status)\n" +
            "        value (#{brandName},#{companyName},#{ordered},#{description},#{status});")
    @ResultMap("brandResultMap")
    void add(Brand brand);


    /*
    * 根据id查询
    * */
    @Select("select * from tb_brand where id=#{id}")
    @ResultMap("brandResultMap")
    Brand selectById(int id);


    /*
    * 修改数据
    * */
    @Update("update tb_brand set brand_name=#{brandName},company_name=#{companyName},ordered=#{ordered},description=#{description},status=#{status} where id=#{id};")
    @ResultMap("brandResultMap")
    void update(Brand brand);

    /*
    * 根据id删除
    * */
    @Delete("delete from tb_brand where id=#{id};")
    @ResultMap("brandResultMap")
    void deleteById(int id);

    /*
    * 根据id动态批量删除
    * */
    @ResultMap("brandResultMap")
    void deleteByIds(@Param("ids") int[] ids);

    /*
     * 分页查询
     * */
    @Select("select * from tb_brand limit #{begin}, #{size}")
    @ResultMap("brandResultMap")
    List<Brand> selectByPage(@Param("begin") int begin,@Param("size") int size);

    /*
     * 查询数据总数
     * */
    @Select("select count(*) from tb_brand")
    int selectTotalCount();


    /*
     * 分页条件查询
     * */


    List<Brand> selectByPageAndCondition(@Param("begin") int begin,@Param("size") int size,@Param("brand")Brand brand);

    /*
     * 查询数据总数
     * */


    int selectTotalCountByCondition(Brand brand);
}
